import 'package:flutter/material.dart';
import 'package:wanAndroid/common/uts/ui_uts.dart';
import 'package:wanAndroid/config/AppConfig.dart';
import 'package:wanAndroid/page/page_login.dart';
import 'package:wanAndroid/res/colors.dart';

class PageRegister extends StatefulWidget {
  static Future<void> start(
      BuildContext context, Map<String, dynamic> args) async {
    return await Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => PageRegister(),
        ));
  }

  ///启动页
  static Future<void> startAndRemove(BuildContext context) async {
    return await Navigator.pushAndRemoveUntil(
      context,
      MaterialPageRoute(builder: (context) => PageRegister()),
      (r) => r == null,
    );
  }

  @override
  State<StatefulWidget> createState() => _PageRegister();
}

class _PageRegister extends State<PageRegister> {
  /// 用户
  String _username;

  ///密码
  String _password;

  /// 确认密码
  String _repassword;

  @override
  Widget build(BuildContext context) => Scaffold(
        resizeToAvoidBottomInset: false,
        appBar: AppBar(
          title: UiUts.getTitle("注\t\t册"),
          centerTitle: true,
        ),
        body: Stack(
          children: [
            ///  登录页面操作
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                mainAxisSize: MainAxisSize.max,
                children: [
                  /// 用户名
                  Container(
                    margin: const EdgeInsets.only(
                      left: 15,
                      right: 15,
                      top: 50,
                    ),
                    child: TextField(
                      onChanged: (v) {
                        setState(() {
                          _username = v;
                        });
                      },
                      minLines: 1,
                      decoration: InputDecoration(
                        labelText: "账号",
                        hintText: "请输入账号",
                        hintStyle: TextStyle(
                          color: Color(0xff999999),
                          fontSize: 12,
                        ),
                      ),
                    ),
                  ),

                  /// 密码
                  Container(
                    margin: const EdgeInsets.only(
                      left: 15,
                      right: 15,
                      top: 10,
                    ),
                    child: TextField(
                      onChanged: (v) {
                        setState(() {
                          _password = v;
                        });
                      },
                      obscureText: true,
                      maxLines: 1,
                      decoration: InputDecoration(
                        labelText: "密码",
                        hintText: "请输入密码",
                        hintStyle: TextStyle(
                          color: Color(0xff999999),
                          fontSize: 12,
                        ),
                      ),
                    ),
                  ),

                  ///确认密码
                  Container(
                    margin: const EdgeInsets.only(
                      left: 15,
                      right: 15,
                      top: 10,
                    ),
                    child: TextField(
                      onChanged: (v) {
                        setState(() {
                          _repassword = v;
                        });
                      },
                      obscureText: true,
                      maxLines: 1,
                      decoration: InputDecoration(
                        labelText: "确认密码",
                        hintText: "请输入密码",
                        hintStyle: TextStyle(
                          color: Color(0xff999999),
                          fontSize: 12,
                        ),
                      ),
                    ),
                  ),

                  UiUts.getDivider(height: 10),

                  ///登录
                  Container(
                    constraints: BoxConstraints(
                      maxHeight: 50,
                    ),
                    margin: const EdgeInsets.symmetric(
                      horizontal: 15,
                      vertical: 10,
                    ),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(colors: <Color>[
                        Colors.blue.shade300,
                        Colors.blue.shade500,
                        Colors.blue.shade700
                      ]),
                      borderRadius: BorderRadius.circular(8),
                    ),
                    child: TextButton(
                      onPressed: () {},
                      child: UiUts.getText(
                        "立即注册",
                        color: Colors.white,
                        fontSize: 17,
                      ),
                    ),
                  ),
                ],
              ),
            ),

            ///注册按钮
            Positioned(
              bottom: 50,
              left: 0,
              right: 0,
              child: TextButton(
                child: UiUts.getText(
                  "有账号？去登陆",
                  color: ResColors.primaryColor,
                  fontSize: 14,
                ),
                onPressed: () {
                  PageLogin.startAndRemove(context);
                },
              ),
            ),
          ],
        ),
      );
}
